package de.cau.apo.problems.binpacking;

import java.util.ArrayList;
import java.util.List;

/**
 * This class represents a bin for the bin packing problem.
 * It just consists of a fixed index and of list of items that are packed in this bin.
 * 
 * @author Marius Richter
 */
public class Bin {

	// ########### properties ###########
	
	/** the index of this bin */
	public final int index;
	/** the list of items that are packed in this bin. */
	public final List<Item> items = new ArrayList<Item>();
	
	// ########### initialization ###########
	
	/**
	 * Creates a new bin object
	 * @param index the index for this bin
	 */
	public Bin(int index) {
		this.index = index;
	}
	
	// ########### getter/setter ###########
	
	/**
	 * @return the index of this bin
	 */
	public int getIndex() {
		return index;
	}
	
	/**
	 * @return the list items that are packed in this bin
	 */
	public List<Item> getItems() {
		return items;
	}
	
	/**
	 * @param item the item that shall be added to this bin
	 * @return true if adding was successful, false otherwise
	 */
	public boolean addItem(Item item) {
		return this.items.add(item);
	}
	
	/**
	 * @param item the item that shall be removed from this bin
	 * @return true if removing was successful, false otherwise
	 */
	public boolean removeItem(Item item) {
		return this.items.remove(item);
	}
	
	/**
	 * @return the size of this bin, that is the sum of the sizes 
	 * of all the items that are packed in this bin
	 */
	public int getSize() {
		int size = 0;
		for (Item item : this.items) {
			size += item.getSize();
		}
		return size;
	}

	// ########### overriding toString() ###########
	
	@Override
	public String toString() {
		return "Bin [items=" + items + "]";
	}
	
}
